package com.wing.ext.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wing.common.util.GUID;
import com.wing.common.util.PageBean;
import com.wing.ext.dao.ProductsDao;
import com.wing.ext.domain.Products;
/**
 * 
 * @author wyf
 * 
 */
@Service
@Transactional
public class ProductsManager {
	@Autowired
	private ProductsDao productsdao;
	
	
	/**
	 * 获得该对象所有数据的列表
	 * 
	 * @return list
	 */
	public List<Map<String,Object>> findAll(){
		return productsdao.findAll();	 
	}
	
	public PageBean findPageList(int currentPage, int pageSize, Object... args){
		return productsdao.findPageList(currentPage,pageSize,args);	 
	}
	
	
	/**
	 * 通过id得到对象
	 *
	 * @param  id
	 * @return pObject
	 */
	public Products findById(String id){
		return productsdao.findById(id);	 
	}
	
	/**
	 * 保存对象
	 *
	 * @param  products
	 */
	public void saveProducts(Products products){
		if(products.getId() == null ||  "".equals(products.getId())){
			products.setId(new GUID().toString());
			productsdao.insert(products);
		}else{
			productsdao.update(products);
		}
	}

	/**
	 * 编辑对象
	 *
	 * @param  products
	 */
	public void updateProducts(Products products){
		productsdao.update(products);
	}
	
	 /**
	 * 删除对象
	 *
	 * @param  chk 对象id数组
	 */
	public void deleteProductss(String[] chk) {
		for(int i=0;i<chk.length;i++){
			productsdao.delete(chk[i]);
		}
	}

	public Map getFistProductsByGrpId(String grpId) {
		List list = productsdao.findProductsByGrpId(grpId);
		Map map = new HashMap();
		if(list.size()>0){
			map = (Map)list.get(0);
		}
		return map;
	}
}



